﻿@{
    Layout = null;
}
@using Models
@{
    UO_Organization org = ViewBag.org as UO_Organization;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link href="~/Content/AUI/css/aui.css" type="text/css" rel="stylesheet" />
    <link href="~/Content/AUI/css/aui-flex.css" type="text/css" rel="stylesheet" />
    <link href="~/Content/AUI/css/Calendar.css" rel="stylesheet" />
</head>
<body>
    <div class="aui-center">
        <header class="aui-bar aui-bar-nav aui-bar-light">
            <a tapmode onclick="javascript: history.go(-1)" class="aui-pull-left"><span class="aui-iconfont aui-icon-left"></span></a>
            <span style="margin-left:-50px">预约体检日期</span>
        </header>
    </div>
    <div class="aui-content" id="calendar_content">
        <input type="hidden" value="@org.OrgName" id="orgName" />
        <div id="calendar" class="aui-calendar"></div>
    </div>
    <footer class="aui-bar aui-bar-tab">
        <div class="aui-bar aui-bar-nav aui-bar-btn-sm" onclick="submit()">
            提交预约
        </div>
    </footer>
</body>
</html>
<script src="~/Content/AUI/script/api.js"></script>
<script src="~/Content/AUI/script/aui-tap.js"></script>
<script src="~/Content/AUI/script/aui-calendar.js"></script>
<script src="~/Content/AUI/script/aui-dialog.js"></script>
<script src="~/Content/AUI/script/aui-toast.js"></script>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
    var todayDate = new Date();
    var startDate = todayDate.getFullYear() + '-' + (todayDate.getMonth() + 1) + '-' + todayDate.getDate();
    var endDate = (todayDate.getFullYear()) + '-' + (todayDate.getMonth() + 1);
    var windowHeight = $(window).height(),
               $body = $("#calendar_content");
    $body.css("height", windowHeight); //重要代码
    $("#calendar_content").on("touchstart", function (e) {
        e.preventDefault();//取消事件的默认动作。
        startX = e.originalEvent.changedTouches[0].pageX,
        startY = e.originalEvent.changedTouches[0].pageY;
    });
    $("#calendar_content").on("touchmove", function (e) {
        e.preventDefault();//取消事件的默认动作。
        moveEndX = e.originalEvent.changedTouches[0].pageX,
        moveEndY = e.originalEvent.changedTouches[0].pageY,
        X = moveEndX - startX,
        Y = moveEndY - startY;
        if (Math.abs(X) > Math.abs(Y) && X > 0) {
            // alert("向右滑");
            var startYear = startDate.substr(0, 4);//获取当前容器的年份
            var startmonth = endDate.substring(5);//获取当前容器的月份
            if (startmonth < 2) {
                startYear = parseInt(startYear) - 1;
                startmonth = 12;
            } else {
                startmonth = parseInt(startmonth) - 1;
            }
            if (startYear == todayDate.getFullYear())//判断是否为当前年份
            {
                if (startmonth < todayDate.getMonth() + 1) {
                    alert("前面没有可预约的体检了···");
                    return;
                }
            }
            if (startmonth == (todayDate.getMonth() + 1)) {//判断是否为当前月份
                startDate = todayDate.getFullYear() + '-' + (todayDate.getMonth() + 1) + '-' + todayDate.getDate();
                endDate = (todayDate.getFullYear()) + '-' + (todayDate.getMonth() + 1);
            } else {
                startDate = startYear + "-" + startmonth + "-" + 1;
                endDate = startYear + "-" + startmonth;
            }
            calendar = new auiCalendar({
                container: document.getElementById("calendar"),
                startDate: startDate,
                endDate: endDate,
                lunarShow: true,
                dateActive: dateActive,
                beforeStartDateClick: false
            });
        }
        else if (Math.abs(X) > Math.abs(Y) && X < 0) {
            //alert("向左滑");
            var startYear = startDate.substr(0, 4);
            var startmonth = endDate.substring(5);
            if (startmonth > 11) {
                startYear = parseInt(startYear) + 1;
                startmonth = 1;
            } else {
                startmonth = parseInt(startmonth) + 1;
            }
            startDate = startYear + "-" + startmonth + "-" + 1;
            endDate = startYear + "-" + startmonth;
            calendar = new auiCalendar({
                container: document.getElementById("calendar"),
                startDate: startDate,
                endDate: endDate,
                lunarShow: true,
                dateActive: dateActive,
                beforeStartDateClick: true
            });
        }
    });
    var calendar = new auiCalendar({
        container: document.getElementById("calendar"), //容器
        startDate: startDate,//开始日期
        endDate: endDate,//结束日期
        lunarShow: true,//是否显示农历
        dateActive: dateActive,//点击日期后回调
        beforeStartDateClick: false//设置今天之前日期是否可点击
    });
    var tmp = "";
    function dateActive(date) {
        tmp = date;
    }
    //点击提交预约按钮
    function submit() {
        if (tmp == "" || tmp == null) {
            alert("请选择要预约的日期！");
            return;
        }
        if (tmp == todayDate.getFullYear() + '-' + (todayDate.getMonth() + 1) + '-' + todayDate.getDate()) {
            alert("不可预约当天的体检！");
            return;
        }
        else {
            var dialog = new auiDialog();
            dialog.alert({
                title: "预约信息确认",
                msg: '预约分院：' + $("#orgName").val() + '</br>体检日期:' + tmp,
                buttons: ['取消', '确定']
            }, function (ret) {
                if (ret.buttonIndex == 1) {
                    history.go(0);
                }
                else {
                    if (ret.buttonIndex == 2) {
                        PostBookSinglearrange(tmp);
                    }
                }
            });
        }
    }
    //提交预约申请
    function PostBookSinglearrange(tmp) {
        $.ajax({
            type: "Get",
            url: "/Mobile/Store/PostBookSinglearrange?id=" + tmp,
            //data: { tmp: tmp },
            success: function (result) {
                result = eval("(" + result + ")");//转换为json对象
                if (result.IsSuccess) {
                    //alert(result.Message);
                    location.href = '/Mobile/Store/OrderRecord';
                }
                if (!result.IsSuccess) {
                    alert(result.Message);
                    history.back(-1);
                }
            }
        });
    }
</script>